<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link href="<s:url value="/css/style.css"/>" rel="stylesheet"
			type="text/css" />
		<script type="text/javascript" src="<s:url value="/js/common.js"/>"></script>
		<script type="text/javascript"
			src="<s:url value="/js/jquery-1.3.2.min.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.bgiframe.min.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.ajaxQueue.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/thickbox-compressed.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.autocomplete.js"/>"></script>
		<link rel="stylesheet" type="text/css"
			href="<s:url value="/js/autocomplete/jquery.autocomplete.css"/>" />
		<link rel="stylesheet" type="text/css"
			href="<s:url value="/js/autocomplete/thickbox.css"/>" />
		<script type="text/javascript"
			src="<s:url value="/js/jquery.blockUI.js"/>"></script>
		<link href="<s:url value="/css/jquery.css"/>" rel="stylesheet"
			type="text/css" />
		<script type="text/javascript" src="<s:url value="/js/jquery-ui.js"/>"></script>
		<script type="text/javascript">
	    $(document).ready(function(){
	         $("#selStudent").autocomplete("<s:url value="/customer/Leads/autoCompleteAjax.action"/>", {
	              width: 300,
	              minChars:2, //几个字
	              mastMatch:true,
	              selectFirst: false,
	              max:  20,
	           	  formatItem: function(row, i, max) {
	           	      //alert(row);
	           	      var d=eval("("+row+")");
	           	      //alert(d);
				      return  d.name+" "+ d.card +" " + d.tel;
		         },
			     formatMatch: function(row, i, max) {
			         var d=eval("("+row+")");
	 			     return  d.name+" "+ d.card +" " + d.tel;
			     },
			     formatResult: function(row) {
			        // alert(row);
			         var d=eval("("+row+")");
				     return d.name+" "+ d.card ;
	     	      }
             });
             $("#selStudent").result(function(event, data, formatted) {
           	      var d=eval("("+data+")");
		          $("#selStudentId").val(d.id);
             });
             $("#selTime").change(function(){
                   $('#selClassEntityId').val("");
             });
             $('#selDate').datepicker(
	    	      { dateFormat:'yy-mm-dd',
	    	        onSelect: function(dateText, inst) {
	    	           $('#selTime').val("");
	    	           $('#selClassEntityId').val("");
	    	           $('#listForm').submit();
	    	        }
	    	      }
	    	 );
    });
   //选到某节课
    function doSelectCheckinEntityById(Eid){
          var o=$('#selClassEntityId').val();
          if  (o==Eid){
            return;
          }
          $("#"+Eid).css({'background-color' : "#A7CDF7", 'font-weight' : 'bolder'});
          var o=$('#selClassEntityId').val();
          if (o){
            $("#"+o).css({'background-color' : "#D7E9FC", 'font-weight' : 'normal'});
          }
          $('#selClassEntityId').val(Eid);
          $('#listForm').submit();
    };
    function doSubmit() {
    	$('#listForm').submit();
	};
	function goDetail() {
	   var sid=$("#selStudentId").val();
	   if (!sid){
	      alert("please select a  student ");
	      return ;
	   }
	   var year=$("#year").val();
	   var week=$("#week").val();
 	   var url="<%=basePath%>customer/PersonalTouch/bookingEdit?id="+sid+"&year="+year+"&week="+week;
 	   var aa=window.open(url,"_blank");  
	};
   function goSearchStudent() {
	   var sid=$("#selStudentId").val();
	   if (!sid){
	      alert("please select a  student ");
	      return ;
	   }
	    var t=$('#listForm');
        t.attr('action',t.attr('action').replace('list','listLeadsClassEntity'));
		$('#listForm').submit();
	};
	function goBooking() {
	    var sid=$("#selStudentId").val();
	    if (!sid){
	       alert("please select a  student ");
	       return ;
	    }
	    var year=$("#year").val();
	    var week=$("#week").val();
	    var url="<%=basePath%>academic/ClassBooking/beforeBooking?selLeadsId="+sid+"&year="+year+"&week="+week;
 	    var aa=window.open(url,"_blank","resizable=no,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,fullscreen=yes");  
	};
	function changeBookingStatus(leadsClassId,classEntityId,type){
	    $('#selleadsClassEntityId').val(leadsClassId);
        $('#selClassEntityId').val(classEntityId);
        doChangeBookingStatus(type,'0');
	};
	function doChangeBookingStatus(type,comfirm){
       $.blockUI({ css: { 
              border: 'none', 
              padding: '15px', 
              backgroundColor: '#000', 
              '-webkit-border-radius': '10px', 
              '-moz-border-radius': '10px', 
              opacity: .5, 
              color: '#fff' 
       } });  
       var url = "<s:url value="/academic/ClassBooking/changeBookingStatus.action"/>";
       var params = {
          id:$('#selleadsClassEntityId').val(),
          type:type,
          confirm:comfirm
       };
       jQuery.post(url, params, callbackFunChangeBooking);	
	};
    function doBooking(comfirm){
          var  classentityid=$('#selClassEntityId').val();
          var  selstudentid=$("#selStudentId").val();
          if (!classentityid||!selstudentid){
             alert("please select one class and one student");
             return;
          }
          $.blockUI({ css: { 
                    border: 'none', 
                    padding: '15px', 
                    backgroundColor: '#000', 
                    '-webkit-border-radius': '10px', 
                    '-moz-border-radius': '10px', 
                    opacity: .5, 
                    color: '#fff' 
         }});
         var url = "<s:url value="/academic/ClassBooking/doBooking.action"/>";
         var params = {
               selClassEntityId:classentityid,
               selLeadsId:selstudentid,
               type:"NORMAL",
               confirm:comfirm
         };
         jQuery.post(url, params, callbackFunBooking);
     };
	 function callbackFunBooking(data){
              setTimeout($.unblockUI, 500); 
              $(data).find('response').each(function(){　　　　　　　　　　　　　　　　　　
　 　　　　　　　　  var type= $(this).children("type").text() ;
                  if (type==="ok"){
                       var info=$(this).children("info").text() ;
                       alert(info);
                       $('#listForm').submit();
                       return;
                   }else if  (type==="warn"){
                       var msg=$(this).children("info").text();
                       $("#info").val(msg);
                       var type= $(this).children("dotype").text() ;
                       var confirmmsg= $(this).children("confirm").text() ;
                       if(confirm(msg)){
		                    doBooking(confirmmsg);
	                   }else{ 
	                        return;
 	                   }
                  }else if  (type==="error"){
                      $("#info").val($(this).children("info").text());
                      alert($(this).children("info").text());
                  }
  　　　　　　　 });
 　　　      };
        function callbackFunChangeBooking(data){
              setTimeout($.unblockUI, 500); 
              $(data).find('response').each(function(){　　　　　　　　　　　　　　　　　　
　 　　　　　　　　  var type= $(this).children("type").text() ;
                  if (type==="ok"){
                       var info=$(this).children("info").text() ;
                       alert(info);
                       $('#listForm').submit();
                       return;
                   }else if  (type==="warn"){
                       var msg=$(this).children("info").text();
                       $("#info").val(msg);
                       var type= $(this).children("dotype").text() ;
                       var confirmmsg= $(this).children("confirm").text() ;
                       if(confirm(msg)){
		                    doChangeBookingStatus(type,confirmmsg);
		                    return;
	                   }else{ 
	                        return;
 	                   }
                  }else if  (type==="error"){
                      $("#info").val($(this).children("info").text());
                      alert($(this).children("info").text());
                  }
  　　　　　　　 });
 　　　      };
  function goExport(){
	var url='<s:url value="/academic/ClassBooking/export" />';
	 location.href=url;
	// window.showModalDialog(url,'xx','dialogWidth:600px;dialogHeight:285px;');
 }
    </script>
	</head>
	<body>
		<s:include value="/common/up.jsp"></s:include>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td class="box">
					<s:form action="ClassBooking/list" name="listForm" id="listForm"
						namespace="/academic">
						<table width="100%" border="0" cellpadding="0" cellspacing="0"
							class="searchbg">
							<tr>
								<td>
									<s:hidden id="selleadsClassEntityId"
										name="selleadsClassEntityId" />
									<input type="hidden" id="startIndex" name="startIndex"
										value="0" />
									Date:
									<s:date name="selDate" format="yyyy-MM-dd" var="showTimefmt" />
									<s:textfield value="%{#showTimefmt}" size="8" name="selDate"
										id="selDate" />
									Time
									<s:select id="selTime" name="selTime" headerKey=""
										headerValue="---all----" list="checkMessageMap" listKey="key"
										listValue="value" />
									W
									<s:checkbox name="isWaiting"></s:checkbox>
									<img src="<s:url value="/img/right/btns.gif"/>" border="0"
										onclick="javascript:doSubmit();" align="absmiddle" />
								</td>
								<td>
									Student:
									<s:textfield id="selStudent" size="16" name="selLeads.name" />
									<s:hidden id="selStudentId" name="selLeadsId" />
									<img src="<s:url value="/img/right/Detail.gif"/>" border="0"
										onclick="javascript:goDetail();" align="absmiddle" />
									<img src="<s:url value="/img/right/Add.gif"/>" border="0"
										onclick="javascript:doBooking('0');" align="absmiddle" />
									Year:
									<s:select id="year" list="{2008,2009,2010,2011}" name="year">
									</s:select>
									Week:
									<s:select id="week"
										list="{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52}"
										name="week">
									</s:select>
									<img src="<s:url value="/img/right/btns.gif"/>" border="0"
										onclick="javascript:goSearchStudent();" align="absmiddle" />
									<img src="<s:url value="/img/right/Booking.gif"/>" border="0"
										onclick="javascript:goBooking('0');" align="absmiddle" />
									<img onclick="goExport();"
										src="<s:url value="/img/right/Export.gif"/>" border="0"
										align="absmiddle" />
								</td>
							</tr>
						</table>
						<table>
							<tr>
								<td>
									<table id="classtable" class="box2" cellpadding="1"
										cellspacing="1">
										<s:set var="cols" value="10" />
										<s:set var="classEntityId" value="selClassEntityId" />
										<s:hidden name="selClassEntityId" id="selClassEntityId" />
										<s:iterator value="allClassEntity" status="st">
											<s:if test="#st.index % #cols == 0">
												<tr>
											</s:if>
											<s:if test="id==#classEntityId">
												<td id="<s:property value="id" />" bgcolor="#A7CDF7"
													align="center" style="font-weight: bolder"
													onclick="javascript:doSelectCheckinEntityById('<s:property value="id" />');">
													<s:property value="message" />
												</td>
											</s:if>
											<s:else>
												<td id="<s:property value="id" />" class="tablecolour2"
													onclick="javascript:doSelectCheckinEntityById('<s:property value="id" />');">
													<s:property value="message" />
												</td>
											</s:else>
											<s:if test="(#st.index+1) % #cols == 0">
												</tr>
											</s:if>
											<s:elseif test="#st.last">
												<s:bean name="org.apache.struts2.util.Counter">
													<s:param name="first" value="(#st.index+1) % #cols" />
													<s:param name="last" value="#cols - 1" />
													<s:iterator>
														<td class="tablecolour2">
															&nbsp;
														</td>
													</s:iterator>
												</s:bean>
												</tr>
											</s:elseif>
										</s:iterator>
									</table>
								</td>
							</tr>
						</table>
						<table id="curLeadsClasses" width="100%" border="0"
							cellpadding="0" cellspacing="1" class="box2">
							<tr>
								<td class="tablecolour1">
									NO.
								</td>
								<td class="tablecolour1">
									Student Info
								</td>
								<td class="tablecolour1">
									Class Type
								</td>
								<td class="tablecolour1">
									Class Time
								</td>
								<td class="tablecolour1">
									Booking Time
								</td>
								<td class="tablecolour1">
									Checkin Time
								</td>
								<td class="tablecolour1">
									Cancel Time
								</td>
								<td class="tablecolour1">
									Status
								</td>
								<td class="tablecolour1">
									Function
								</td>
							</tr>
							<s:iterator value="listResult.items" status="status">
								<tr title="entity">
									<td class="tablecolour2">
										<s:property value="#status.index+1" />
									</td>
									<td class="tablecolour2">
										<s:property value="leads.name" />
										[
										<s:property value="leads.mobileTelephone" />
										] [
										<s:property value="leads.eliteCard" />
										]
									</td>
									<td class="tablecolour2">
										<s:property value="classEntity.arrangeMessage" />
									</td>
									<td class="tablecolour2">
										<s:date format="yyyy-MM-dd[E]" name="classEntity.classDate" />
										<s:property value="classEntity.classTime" />
									</td>
									<td class="tablecolour2">
										<s:date format="yyyy-MM-dd HH:mm:ss" name="bookingTime" />
									</td>
									<td class="tablecolour2">
										<s:date format="yyyy-MM-dd HH:mm:ss" name="checkinTime" />
									</td>
									<td class="tablecolour2">
										<s:date format="yyyy-MM-dd HH:mm:ss" name="cancelTime" />
									</td>
									<td class="tablecolour2">
										<s:property value="status" /><s:property value="comments" />
									</td>
									<td class="tablecolour2">
										<s:if test="isManager()">
											<s:if test="status == 'Booking'">
												<a href='#'
													onclick="changeBookingStatus('<s:property value="id"/>','<s:property value="classEntity.id"/>','CANCEL');">Cancel</a>
											</s:if>
											<s:if test="status == 'Absence'">
												<a href='#'
													onclick="changeBookingStatus('<s:property value="id"/>','<s:property value="classEntity.id"/>','CANCEL');">Cancel</a>
											</s:if>
											<s:if test="status == 'Waiting'">
												<a href='#'
													onclick="changeBookingStatus('<s:property value="id"/>','<s:property value="classEntity.id"/>','NORMAL');">Booking</a>
											</s:if>
										</s:if>
										<s:else>
											<s:if test="status == 'Booking'">
												<a href='#'
													onclick="changeBookingStatus('<s:property value="id"/>','<s:property value="classEntity.id"/>','CANCEL');">Cancel</a>
											</s:if>
											<s:if test="status == 'Waiting'">
												<a href='#'
													onclick="changeBookingStatus('<s:property value="id"/>','<s:property value="classEntity.id"/>','NORMAL');">Booking</a>
											</s:if>
										</s:else>
									</td>
								</tr>
							</s:iterator>
						</table>
						<s:include value="/common/page.jsp"></s:include>
					</s:form>
				</td>
			</tr>
		</table>
		<s:include value="/common/down.jsp"></s:include>
	</body>
</html>
